<template>
    <el-select v-model="value" placeholder="请选择优惠券类型" clearable @change="handleChange" style="width:100%">
        <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
        </el-option>
    </el-select>
</template>

<script>

    export default {
        props: {
            category: [Number, String]
        },
        data() {
            return {
                value: {},
                options: []
            };
        },
        watch: {
            category(value) {
                this.value = value;
            }
        },
        mounted() {
            this.getCategoryList();
        },
        methods: {
            handleChange(value) {
                this.$emit('update:category', value);
            },
            getCategoryList() {
                axios
                    .get('admin_bonus_categories', {params: {pageSize: 999}})
                    .then(res => res.data ? res.data.data.map(item => ({value: item.id, label: item.name})) : [])
                    .then(data => {
                        this.options = data;
                    });
            }
        }
    };
</script>
